package com.itheima.controller;

import com.itheima.domain.User;
import com.itheima.factory.UserFactory;
import com.itheima.service.RoleService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestDemo {
        /**
         *
         * 测试获取bean对象的三种方式*/
    @Test
    public void test1(){

        ApplicationContext ca = new ClassPathXmlApplicationContext("spring.xml");

        /*通过获取ioc中的bean对象*/
        RoleService roleService = (RoleService)ca.getBean("roleService");
        roleService.say();
        /*通过字节码类型获得 若果容器中存在多个相同的对象类型时  会出现不知道选哪一个的错误*/

        User bean = ca.getBean(User.class);
        bean.eat();
        //推荐使用这一种:第一二种方式的结合体
        User u = ca.getBean("user", User.class);
        u.eat();





    }


}
